package org.zky.modules.account.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.zky.aop.log.Log;
import org.zky.modules.account.domain.ZkyAdminAccountTab;
import org.zky.modules.account.service.ZkyAdminAccountTabService;
import org.zky.modules.account.service.dto.ZkyAdminAccountTabQueryCriteria;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
* @author chenglong
* @date 2020-03-23
*/
@Api(tags = "account管理")
@RestController
@RequestMapping("/api/zkyAdminAccountTab")
public class ZkyAdminAccountTabController {

    private final ZkyAdminAccountTabService zkyAdminAccountTabService;

    public ZkyAdminAccountTabController(ZkyAdminAccountTabService zkyAdminAccountTabService) {
        this.zkyAdminAccountTabService = zkyAdminAccountTabService;
    }

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('zkyAdminAccountTab:list')")
    public void download(HttpServletResponse response, ZkyAdminAccountTabQueryCriteria criteria) throws IOException {
        zkyAdminAccountTabService.download(zkyAdminAccountTabService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询account")
    @ApiOperation("查询account")
    @PreAuthorize("@el.check('zkyAdminAccountTab:list')")
    public ResponseEntity<Object> getZkyAdminAccountTabs(ZkyAdminAccountTabQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(zkyAdminAccountTabService.queryAll(criteria,pageable), HttpStatus.OK);
    }

    @PostMapping
    @Log("新增account")
    @ApiOperation("新增account")
    @PreAuthorize("@el.check('zkyAdminAccountTab:add')")
    public ResponseEntity<Object> create(@Validated @RequestBody ZkyAdminAccountTab resources){
        return new ResponseEntity<>(zkyAdminAccountTabService.create(resources), HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改account")
    @ApiOperation("修改account")
    @PreAuthorize("@el.check('zkyAdminAccountTab:edit')")
    public ResponseEntity<Object> update(@Validated @RequestBody ZkyAdminAccountTab resources){
        zkyAdminAccountTabService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @Log("删除account")
    @ApiOperation("删除account")
    @PreAuthorize("@el.check('zkyAdminAccountTab:del')")
    @DeleteMapping
    public ResponseEntity<Object> deleteAll(@RequestBody Long[] ids) {
        zkyAdminAccountTabService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}